<html lang="en">
<head>
    <title>攻略分类管理</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script>
        $(function () {
            $(".editStrategyCatalogBtn").click(function () {
                //重置表单
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                if(json) {
                    $("#editForm input[name='name']").val(json.name)
                    $("#editForm input[name='sequence']").val(json.sequence)
                    $("#editForm select[name='state']").val(json.state + "")
                    $("#editForm input[name='id']").val(json.id)
                    $("#editForm select[name='strategy.id']").val(json.strategyId);
                }
                $("#editModal").modal("show");
            })
            //修改操作
            $(".saveBtn").click(function () {
                //提交表单之前判断是否选中推荐的类型,如果不等于-1,在提交表单,否则不提交表单
                $('#editForm').ajaxSubmit({
                    beforeSubmit:function (params) {
                        var type = $("#editForm select[name='type']");
                        if (type.val()==-1) {
                            $.messager.alert("温馨提示","请选择推荐的类型")
                            return false;
                        }
                        },
                    success:function (data) {
                        if(data.success){
                            window.location.reload();
                        }else {
                            $.messager.alert("温馨提示",e.msg);
                        }
                    }
                })
            })
           
        })

    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="strategyCatalog">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">所属攻略:</label>
                    <div class="form-group" >
                        <div class="col-sm-6">
                            <select id="strategyId" name="strategyId"  class="form-control">
                                <option value="-1">--请选择--</option>
                                <#list strategys as s>
                                 <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                            <script>
                                $("#strategyId").val(${qo.strategyId})
                            </script>
                        </div>
                    </div>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>
                <a id="btn_query" class="btn btn-info editStrategyCatalogBtn"><span class="glyphicon glyphicon-search"></span>添加攻略分类</a>


            </form>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>分类名称</th>
                    <th>所属分类</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>编辑</th>
                </tr>
                </thead>
               <#list result.list as entity >
                     <tr>
                         <td>${(entity.name)!}</td>
                         <td>${(entity.strategy.title)!}</td>
                         <td>${(entity.sequence)!}</td>
                         <td>${entity.stateDisplay}</td>
                         <td>
                             <a href="javascript:;" class="btn editStrategyCatalogBtn" data-json='${entity.jsonString!}'>修改</a>
                         </td>
                     </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--攻略分类编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">攻略分类编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" value="" placeholder="请输入名称">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select name="strategy.id" class="form-control">
                                <option value="-1">--请选择--</option>
                                <#list strategys as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">排序：</label>
                        <div class="col-sm-6">
                            <input type="number" class="form-control" name="sequence" value="">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="-1">--请选择--</option>
                                <option value="true">--启用--</option>
                                <option value="false">--禁用--</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="submit" class="btn btn-primary saveBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
